/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#include "SBJ/Arrow/Channel.h"
#include "MockMessage.h"

#include <boost/test/auto_unit_test.hpp>

BOOST_AUTO_TEST_CASE(HoldMessage)
{
	::printf("HoldMessage\n");
	
	MockSubscriber subscriber;
	
	// Create the channel
	SBJ::Arrow::Channel channel( 0, 0 );
	channel.start();

	// Publish our message type
	SBJ::Arrow::Publication& pub = channel.publish< MockMessage >();
	
	// Create the message
	volatile const char* hit = 0;
	MockMessage msg( hit, pub.makeTopic< MockMessage >( "MyTopic" ), 0, &subscriber );

	// Push the message
	channel.onMessage( msg );
	
	// And test
	::test_sleep( .5 );
	BOOST_CHECK_EQUAL( MockMessage::hit_none, const_cast< char* >( hit ) );
	
	// Have message move forward
		SBJ::Arrow::Subscription sub = channel.makeTypedSubscription< MockMessage >( &subscriber, "MyTopic" );
	sub.activate();

	// And test
	::test_sleep( .5 );
	BOOST_CHECK_EQUAL( MockMessage::hit_dispatch_ToTest, const_cast< char* >( hit ) );
}